package com.ruoyi.hcmain.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hcmain.domain.HcPrich;
import com.ruoyi.hcmain.service.IHcPrichService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 价格Controller
 * 
 * @author ruoyi
 * @date 2023-08-12
 */
@RestController
@RequestMapping("/hcmain/prich")
public class HcPrichController extends BaseController
{
    @Autowired
    private IHcPrichService hcPrichService;

    /**
     * 查询价格列表
     */
    @PreAuthorize("@ss.hasPermi('hcmain:prich:list')")
    @GetMapping("/list")
    public TableDataInfo list(HcPrich hcPrich)
    {
        startPage();
        List<HcPrich> list = hcPrichService.selectHcPrichList(hcPrich);
        return getDataTable(list);
    }

    /**
     * 导出价格列表
     */
    @PreAuthorize("@ss.hasPermi('hcmain:prich:export')")
    @Log(title = "价格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HcPrich hcPrich)
    {
        List<HcPrich> list = hcPrichService.selectHcPrichList(hcPrich);
        ExcelUtil<HcPrich> util = new ExcelUtil<HcPrich>(HcPrich.class);
        util.exportExcel(response, list, "价格数据");
    }

    /**
     * 获取价格详细信息
     */
    @PreAuthorize("@ss.hasPermi('hcmain:prich:query')")
    @GetMapping(value = "/{prichId}")
    public AjaxResult getInfo(@PathVariable("prichId") Long prichId)
    {
        return success(hcPrichService.selectHcPrichByPrichId(prichId));
    }

    /**
     * 新增价格
     */
    @PreAuthorize("@ss.hasPermi('hcmain:prich:add')")
    @Log(title = "价格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HcPrich hcPrich)
    {
        return toAjax(hcPrichService.insertHcPrich(hcPrich));
    }

    /**
     * 修改价格
     */
    @PreAuthorize("@ss.hasPermi('hcmain:prich:edit')")
    @Log(title = "价格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HcPrich hcPrich)
    {
        return toAjax(hcPrichService.updateHcPrich(hcPrich));
    }

    /**
     * 删除价格
     */
    @PreAuthorize("@ss.hasPermi('hcmain:prich:remove')")
    @Log(title = "价格", businessType = BusinessType.DELETE)
	@DeleteMapping("/{prichIds}")
    public AjaxResult remove(@PathVariable Long[] prichIds)
    {
        return toAjax(hcPrichService.deleteHcPrichByPrichIds(prichIds));
    }
}
